package com.app.service.impl;

import com.app.mapper.LoanMapper;
import com.app.model.ConfigModel;
import com.app.model.LoanModel;
import com.app.service.ConfigService;
import com.app.service.LoanService;
import com.app.vo.LoanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoanServiceImpl implements LoanService {
    @Autowired
    private LoanMapper loanMapper;
    @Autowired
    private ConfigService configService;

    @Override
    public void insertLoanInfo(LoanModel model) {
        loanMapper.insert(model);
    }

    @Override
    public LoanVo selectLoanList(Integer page, Integer limit, String startTime, String endTime) {
        page = (page - 1) * limit;
        List<LoanModel> loanModels = loanMapper.selectLoanList(page, limit, startTime, endTime);
        ConfigModel configModel = new ConfigModel();
        configModel.setConType(1);
        List<ConfigModel> configModels = configService.getListByModel(configModel);
        for (int i = 0; i < loanModels.size(); i++) {
            for (int i1 = 0; i1 < configModels.size(); i1++) {
                if (loanModels.get(i).getNation().equals(configModels.get(i1).getId())) {
                    loanModels.get(i).setNationText(configModels.get(i1).getName());
                }
            }
        }
        Integer count = loanMapper.selectLoanCount(startTime, endTime);
        LoanVo vo = new LoanVo();
        vo.setList(loanModels);
        vo.setCount(count);
        return vo;
    }
}
